/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Sintelo.java
 *
 * Created on 27/08/2008, 22:23:05
 */

package sintelo.visao;

import java.io.File;
import sintelo.gerador.GeradorReconhecedores;
import sintelo.persistencia.ArquivoEspecificacao;
import sintelo.persistencia.Especificacoes;
import sintelo.simulador.FabricaGerador;
import sintelo.visao.realce.Realce;
import sintelo.visao.realce.Realces;

/**
 *
 * @author Kieling
 */
public class SinteloNovo extends javax.swing.JFrame {
    
    private Realce realceGramatica;
    private Realce realceLexico;

    /** Creates new form Sintelo */
    public SinteloNovo() {
        initComponents();
        realceGramatica = Realces.getRealceGramatica();
        realceLexico = Realces.getRealceLexico();

        realceLexico.instala(txtLexico);
        realceGramatica.instala(txtSintatico);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPopupMenu1 = new javax.swing.JPopupMenu();
        jToolBar1 = new javax.swing.JToolBar();
        jBNovo = new javax.swing.JButton();
        jBAbrir = new javax.swing.JButton();
        jBSalvar = new javax.swing.JButton();
        jToolBar2 = new javax.swing.JToolBar();
        jBRecortar = new javax.swing.JButton();
        jBCopiar = new javax.swing.JButton();
        jBColar = new javax.swing.JButton();
        jBDesfazer = new javax.swing.JButton();
        jBRefazer = new javax.swing.JButton();
        jToolBar3 = new javax.swing.JToolBar();
        jBLexico = new javax.swing.JButton();
        jBSintatico = new javax.swing.JButton();
        jBExecutar = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jToolBar4 = new javax.swing.JToolBar();
        jButton2 = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        txtMensagens = new javax.swing.JTextPane();
        jSplitPane1 = new javax.swing.JSplitPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtLexico = new javax.swing.JTextPane();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtSintatico = new javax.swing.JTextPane();
        jMenuBar2 = new javax.swing.JMenuBar();
        jMArquivo = new javax.swing.JMenu();
        jMInNovo = new javax.swing.JMenuItem();
        jMIAbrir = new javax.swing.JMenuItem();
        jMISalvar = new javax.swing.JMenuItem();
        jMIScomo = new javax.swing.JMenuItem();
        jSeparator3 = new javax.swing.JSeparator();
        jMISair = new javax.swing.JMenuItem();
        jMenuEditar1 = new javax.swing.JMenu();
        jMIDesfazer = new javax.swing.JMenuItem();
        jMIRefazer = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        jMICopiar = new javax.swing.JMenuItem();
        jMIRecortar = new javax.swing.JMenuItem();
        jMIColar = new javax.swing.JMenuItem();
        jMILimpar = new javax.swing.JMenuItem();
        jMenuExibir1 = new javax.swing.JMenu();
        jMenu1 = new javax.swing.JMenu();
        jMIExecutar = new javax.swing.JMenuItem();
        jMISimula = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JSeparator();
        jMILexico = new javax.swing.JMenuItem();
        jMISintatico = new javax.swing.JMenuItem();
        jMAjuda = new javax.swing.JMenu();
        jMISobre = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jToolBar1.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jToolBar1.setRollover(true);

        jBNovo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sintelo/visao/imagens/novo.png"))); // NOI18N
        jBNovo.setFocusable(false);
        jBNovo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jBNovo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jBNovo);

        jBAbrir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sintelo/visao/imagens/abrir2.png"))); // NOI18N
        jBAbrir.setFocusable(false);
        jBAbrir.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jBAbrir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jBAbrir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBAbrirActionPerformed(evt);
            }
        });
        jToolBar1.add(jBAbrir);

        jBSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sintelo/visao/imagens/salvar.png"))); // NOI18N
        jBSalvar.setFocusable(false);
        jBSalvar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jBSalvar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jBSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBSalvarActionPerformed(evt);
            }
        });
        jToolBar1.add(jBSalvar);

        jToolBar2.setRollover(true);
        jToolBar1.add(jToolBar2);

        jBRecortar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sintelo/visao/imagens/copiar.png"))); // NOI18N
        jBRecortar.setFocusable(false);
        jBRecortar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jBRecortar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jBRecortar);

        jBCopiar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sintelo/visao/imagens/colar2.png"))); // NOI18N
        jBCopiar.setFocusable(false);
        jBCopiar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jBCopiar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jBCopiar);

        jBColar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sintelo/visao/imagens/colar.png"))); // NOI18N
        jBColar.setFocusable(false);
        jBColar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jBColar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jBColar);

        jBDesfazer.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sintelo/visao/imagens/voltar.png"))); // NOI18N
        jBDesfazer.setFocusable(false);
        jBDesfazer.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jBDesfazer.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jBDesfazer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBDesfazerActionPerformed(evt);
            }
        });
        jToolBar1.add(jBDesfazer);

        jBRefazer.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sintelo/visao/imagens/ir.png"))); // NOI18N
        jBRefazer.setFocusable(false);
        jBRefazer.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jBRefazer.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jBRefazer);

        jToolBar3.setRollover(true);
        jToolBar1.add(jToolBar3);

        jBLexico.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sintelo/visao/imagens/lex.png"))); // NOI18N
        jBLexico.setFocusable(false);
        jBLexico.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jBLexico.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jBLexico.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBLexicoActionPerformed(evt);
            }
        });
        jToolBar1.add(jBLexico);

        jBSintatico.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sintelo/visao/imagens/sintatico.png"))); // NOI18N
        jBSintatico.setFocusable(false);
        jBSintatico.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jBSintatico.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jBSintatico);

        jBExecutar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sintelo/visao/imagens/executar.png"))); // NOI18N
        jBExecutar.setFocusable(false);
        jBExecutar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jBExecutar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jBExecutar);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sintelo/visao/imagens/simula2.png"))); // NOI18N
        jButton1.setFocusable(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton1);

        jToolBar4.setRollover(true);
        jToolBar1.add(jToolBar4);

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sintelo/visao/imagens/ajudar2.png"))); // NOI18N
        jButton2.setFocusable(false);
        jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton2);

        getContentPane().add(jToolBar1, java.awt.BorderLayout.NORTH);

        jScrollPane3.setMinimumSize(new java.awt.Dimension(300, 100));
        jScrollPane3.setPreferredSize(new java.awt.Dimension(300, 100));

        txtMensagens.setMaximumSize(new java.awt.Dimension(10000, 120));
        txtMensagens.setMinimumSize(new java.awt.Dimension(300, 100));
        txtMensagens.setPreferredSize(new java.awt.Dimension(300, 100));
        jScrollPane3.setViewportView(txtMensagens);

        getContentPane().add(jScrollPane3, java.awt.BorderLayout.SOUTH);

        jPanel1.setMinimumSize(new java.awt.Dimension(150, 150));
        jPanel1.setPreferredSize(new java.awt.Dimension(300, 250));
        jPanel1.setLayout(new java.awt.BorderLayout());

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Léxico");
        jPanel1.add(jLabel1, java.awt.BorderLayout.NORTH);

        jScrollPane1.setMaximumSize(new java.awt.Dimension(250, 450));
        jScrollPane1.setMinimumSize(new java.awt.Dimension(150, 150));
        jScrollPane1.setPreferredSize(new java.awt.Dimension(300, 250));

        txtLexico.setMinimumSize(new java.awt.Dimension(150, 150));
        txtLexico.setPreferredSize(new java.awt.Dimension(300, 250));
        jScrollPane1.setViewportView(txtLexico);

        jPanel1.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jSplitPane1.setLeftComponent(jPanel1);

        jPanel2.setMinimumSize(new java.awt.Dimension(150, 150));
        jPanel2.setPreferredSize(new java.awt.Dimension(300, 250));
        jPanel2.setLayout(new java.awt.BorderLayout());

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("Sintático");
        jPanel2.add(jLabel2, java.awt.BorderLayout.NORTH);

        jScrollPane2.setMinimumSize(new java.awt.Dimension(150, 150));
        jScrollPane2.setPreferredSize(new java.awt.Dimension(300, 250));

        txtSintatico.setMaximumSize(new java.awt.Dimension(250, 450));
        txtSintatico.setMinimumSize(new java.awt.Dimension(150, 150));
        txtSintatico.setPreferredSize(new java.awt.Dimension(300, 250));
        jScrollPane2.setViewportView(txtSintatico);

        jPanel2.add(jScrollPane2, java.awt.BorderLayout.CENTER);

        jSplitPane1.setRightComponent(jPanel2);

        getContentPane().add(jSplitPane1, java.awt.BorderLayout.CENTER);

        jMArquivo.setText("Arquivo");

        jMInNovo.setText("Novo");
        jMArquivo.add(jMInNovo);

        jMIAbrir.setText("Abrir");
        jMArquivo.add(jMIAbrir);

        jMISalvar.setText("Salvar");
        jMArquivo.add(jMISalvar);

        jMIScomo.setText("Salvar como");
        jMArquivo.add(jMIScomo);
        jMArquivo.add(jSeparator3);

        jMISair.setText("Sair");
        jMArquivo.add(jMISair);

        jMenuBar2.add(jMArquivo);

        jMenuEditar1.setText("Editar");

        jMIDesfazer.setText("Desfazer");
        jMenuEditar1.add(jMIDesfazer);

        jMIRefazer.setText("Refazer");
        jMenuEditar1.add(jMIRefazer);
        jMenuEditar1.add(jSeparator1);

        jMICopiar.setText("Copiar");
        jMenuEditar1.add(jMICopiar);

        jMIRecortar.setText("Recortar");
        jMenuEditar1.add(jMIRecortar);

        jMIColar.setText("Colar");
        jMenuEditar1.add(jMIColar);

        jMILimpar.setText("Limpar");
        jMenuEditar1.add(jMILimpar);

        jMenuBar2.add(jMenuEditar1);

        jMenuExibir1.setText("Exibir");
        jMenuBar2.add(jMenuExibir1);

        jMenu1.setText("Ferramentas");

        jMIExecutar.setText("Executar");
        jMenu1.add(jMIExecutar);

        jMISimula.setText("Simulação");
        jMenu1.add(jMISimula);
        jMenu1.add(jSeparator2);

        jMILexico.setText("Léxico");
        jMenu1.add(jMILexico);

        jMISintatico.setText("Sintático");
        jMenu1.add(jMISintatico);

        jMenuBar2.add(jMenu1);

        jMAjuda.setText("Ajuda");

        jMISobre.setText("Sobre");
        jMAjuda.add(jMISobre);

        jMenuBar2.add(jMAjuda);

        setJMenuBar(jMenuBar2);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBDesfazerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBDesfazerActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_jBDesfazerActionPerformed

    private void jBLexicoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBLexicoActionPerformed
        String elex = txtLexico.getText().trim();
        String esin = txtSintatico.getText();

        try{
            GeradorReconhecedores gerador = FabricaGerador.criaGerador(elex, esin);
            TelaSimulador tela = new TelaSimulador(gerador);
            tela.setVisible(true);
        }catch(Exception e){
            Mensagens.alerta(this, "Erro na definição de linguagem!", "Erro");
        }
    }//GEN-LAST:event_jBLexicoActionPerformed

    private void jBAbrirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBAbrirActionPerformed
        
        Especificacoes e = ArquivoEspecificacao.le(new File("teste.sintelo"));
        txtLexico.setText(e.getEspecificacaoLexica());
        txtSintatico.setText(e.getEspecificacaoSintatica());

        realceLexico.aplica(txtLexico);
        realceGramatica.aplica(txtSintatico);
    }//GEN-LAST:event_jBAbrirActionPerformed

    private void jBSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBSalvarActionPerformed
        Especificacoes e = new Especificacoes(txtLexico.getText(), txtSintatico.getText());
        ArquivoEspecificacao.grava(new File("teste.sintelo"), e);
    }//GEN-LAST:event_jBSalvarActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new SinteloNovo().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBAbrir;
    private javax.swing.JButton jBColar;
    private javax.swing.JButton jBCopiar;
    private javax.swing.JButton jBDesfazer;
    private javax.swing.JButton jBExecutar;
    private javax.swing.JButton jBLexico;
    private javax.swing.JButton jBNovo;
    private javax.swing.JButton jBRecortar;
    private javax.swing.JButton jBRefazer;
    private javax.swing.JButton jBSalvar;
    private javax.swing.JButton jBSintatico;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JMenu jMAjuda;
    private javax.swing.JMenu jMArquivo;
    private javax.swing.JMenuItem jMIAbrir;
    private javax.swing.JMenuItem jMIColar;
    private javax.swing.JMenuItem jMICopiar;
    private javax.swing.JMenuItem jMIDesfazer;
    private javax.swing.JMenuItem jMIExecutar;
    private javax.swing.JMenuItem jMILexico;
    private javax.swing.JMenuItem jMILimpar;
    private javax.swing.JMenuItem jMIRecortar;
    private javax.swing.JMenuItem jMIRefazer;
    private javax.swing.JMenuItem jMISair;
    private javax.swing.JMenuItem jMISalvar;
    private javax.swing.JMenuItem jMIScomo;
    private javax.swing.JMenuItem jMISimula;
    private javax.swing.JMenuItem jMISintatico;
    private javax.swing.JMenuItem jMISobre;
    private javax.swing.JMenuItem jMInNovo;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar2;
    private javax.swing.JMenu jMenuEditar1;
    private javax.swing.JMenu jMenuExibir1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPopupMenu jPopupMenu1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JToolBar jToolBar2;
    private javax.swing.JToolBar jToolBar3;
    private javax.swing.JToolBar jToolBar4;
    private javax.swing.JTextPane txtLexico;
    private javax.swing.JTextPane txtMensagens;
    private javax.swing.JTextPane txtSintatico;
    // End of variables declaration//GEN-END:variables

}
